import { ifEnemyData, bindData } from "../Data/dataBase";
import { GlobalFunction } from "../base/GlobalFunction";

const {ccclass, property} = cc._decorator;

@ccclass
export default class EnemyHpBar extends cc.Component {

    @property(cc.ProgressBar)
    hpBar:cc.ProgressBar = null;

    private _hp:number = 0;
    private _maxHp:number = 0;

    init(data:ifEnemyData){
        this._hp = data.hp;
        this._maxHp = data.maxHp;
        this.refresh();

        bindData("WORLD_DATA", "ENEMY_HP" + data.id, async function(data){
            this._hp = data.Hp;
            this.refresh();
        }.bind(this), this);
    }

    refresh(){
        this.node.getComponent("aniProgress").play(this.hpBar.progress, this._hp/this._maxHp);
    }
}
